import { MessageHandler } from './handlers/messageHandler';
import { Wechaty } from 'wechaty'
import qrcode = require('qrcode-terminal')

const ins = Wechaty.instance()

ins.on('scan', (url, code) => {
    if (code == 408) {
        let imgurl = url.replace(/\/qrcode\//, '/l/')
        qrcode.generate(imgurl, { small: true })
    }
})
.on('login',       user => console.log(`User ${user} logined`))
.on('message',  message => new MessageHandler(message))
.init()

export default ins